package blackstone;

import java.io.File;
import java.util.Collection;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class FileTransfer {
	private final static Logger logger = LogManager.getLogger(FileTransfer.class);
	
	public static boolean encoding(String root, String sourceEncoding, String encoding){
		
		boolean res = false;
        try {
        	Collection<File> javaUTF8FileCol =  FileUtils.listFiles(new File(root), new String[]{"java", "ftl", "xml", "html", "js", "txt", "sql", "properties"}, true); 
        
        	for (File javaUTF8File : javaUTF8FileCol) {
				FileUtils.writeStringToFile(javaUTF8File, FileUtils.readFileToString(javaUTF8File, sourceEncoding), encoding);
				res = true;
        	}
		}catch(Exception e){
			logger.error(e.getMessage());
		}
        
        return res;
	}

	public static boolean encoding(String root, String encoding){
		return encoding(root, encoding, "UTF-8");
	}
	
}
